package com.study.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
        return "-----testA";
    }

    @GetMapping("/testASleep")
    public String testASleep() throws InterruptedException {
        Thread.sleep(6000);
        return "-----testA";
    }

    @GetMapping("/testB")
    public String testB(){
        int i =1/0;
        return "-----testB";
    }

    @GetMapping("/testC")
    @SentinelResource(value = "testC", fallback = "fallbackMethod") //此处value值，一般为@GetMapping属性值去掉斜杠
    public String testC(@RequestParam(value = "id",required = false) Integer id,
                        @RequestParam(value = "name",required = false) String name){
        return "-----testC";
    }



    public String fallbackMethod(Throwable e) {
        return "限流请求连接的兜底方法：" + e.getMessage();
    }


}
